package cn.com.kgo.usermanamge.service.impl;

import cn.com.kgo.common.api.usermanage.RoleService;
import cn.com.kgo.common.api.usermanage.UserService;
import cn.com.kgo.entity.usermanage.RoleEntity;
import cn.com.kgo.entity.usermanage.UserEntity;
import cn.com.kgo.entity.util.KResult;
import cn.com.kgo.usermanamge.dao.RoleDao;
import cn.com.kgo.usermanamge.dao.UserDao;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author keepgoon
 * @Description: TODO
 * @date 2019/5/1715:13
 */
@Component
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;


    @Override
    public String getRole(RoleEntity roleEntity) {
        return null;
    }

    @Override
    public String addRole(RoleEntity roleEntity) {
        roleEntity.setId(IdUtil.fastSimpleUUID());
        if(StringUtils.isBlank(roleEntity.getRoleName())) return KResult.failAdd("新增失败！【角色明不能为空】");
        if(StringUtils.isBlank(roleEntity.getRoleCode())) return KResult.failAdd("新增失败！【角色编码不能为空】");
        int isExistUser = roleDao.getRoleCountByCode(roleEntity.getRoleCode());
        if(isExistUser>0)return KResult.failAdd("新增失败！【该用角色已经存在，请重新输入】");
        int count = roleDao.insert(roleEntity);
        return KResult.add(count);
    }
}
